package com.examples.infobox;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;


public class Label1InfoBox extends Composite {

	Label image, text;
	Button showButton;

	Color white;

	Label1InfoBox(final Composite parent, int style) {

		super(parent, style);

		GridLayout layout = new GridLayout();
		layout = new GridLayout(3, false);
		layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
		layout.verticalSpacing = 10;
		this.setLayout(layout);

		white = new Color(null, 255, 255, 255);

		showButton = new Button(this, SWT.NONE);
		showButton.setText("Expand");
		showButton.pack();
		
		final Composite secondCompositeHolder=new Composite(parent, SWT.NONE);
		secondCompositeHolder.setBackground(new Color(null, 255,255,255));
		
		showButton.addSelectionListener(new SelectionListener() {
			boolean visibility=false; 
			@Override
			public void widgetSelected(SelectionEvent e) {						
				DetailBox secondComposite=new DetailBox(secondCompositeHolder, SWT.NONE);
				secondComposite.setBackground(new Color(null, 200,200,200));
				
				if(!visibility){
					parent.layout();
					visibility=true;
				}else{						
					secondComposite.setBackground(new Color(null, 200,200,200));
					Control[] secondCompoChild = secondCompositeHolder.getChildren();
					for(Control cntrl : secondCompoChild){
						cntrl.dispose();
					}					
					parent.layout();
					visibility=false;
				}				
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}
		});

		image = new Label(this, 0);
		image.setText("Composite 1 :: Label1");

		text = new Label(this, 0);
		text.setText("Composite 1 :: Label1");

		setBackground(white);

		image.setBackground(white);

		text.setBackground(white);

		addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent arg0) {
				Label1InfoBox.this.widgetDisposed(arg0);

			}

		});
		this.pack();

	}

	protected void widgetDisposed(DisposeEvent arg0) {
		// TODO Auto-generated method stub

	}
	
	
	class DetailBox extends Composite{
		
		Label nameLbl, phnLbl;
		Text nameTxt, phnTxt;
		
		DetailBox(final Composite parent, int style) {
			super(parent, style);
			
			GridLayout layout = new GridLayout();
			layout = new GridLayout(2, false);
			layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
			layout.verticalSpacing = 10;
			this.setLayout(layout);

			white = new Color(null, 255, 255, 255);
			
			nameLbl = new Label(this, 0);
			nameLbl.setText("Name : ");
			
			nameTxt = new Text(this, SWT.NO);
			nameTxt.pack();
			
			
			phnLbl = new Label(this, 0);
			phnLbl.setText("Phone : ");
			
			phnTxt = new Text(this, SWT.NO);
			phnTxt.pack();		

			setBackground(white);

			nameLbl.setBackground(white);

			phnLbl.setBackground(white);

			addDisposeListener(new DisposeListener() {

				@Override
				public void widgetDisposed(DisposeEvent arg0) {
					Label1InfoBox.this.widgetDisposed(arg0);

				}

			});
			this.pack();			
		}
	}

}
